(defpackage :base-hints-mixin
  (:use :cl)
  (:export :base-hints-mixin))

(in-package :base-hints-mixin)

(defclass base-hints-mixin ()
  ())

(defmethod p:show-hint-make-selection ((problem base-hints-mixin) transformation selected-nodes selection)
  (let* ((arrows (set-exclusive-or selected-nodes selection))
         (wrong-boxes (set-difference selected-nodes selection))
         ;;(right-boxes (intersection selected-nodes selection))
         (wrong-text (if wrong-boxes
                         (format nil "~%You have selected some incorrect boxes -- click the boxes pointed to by the red arrows to unselect them.")
                         "")))
  (dolist (i arrows)
    (setf (d:arrow i) (if (find i selection)
                          (gwee:color 0 255 0)
                          (gwee:color 255 0 0))))
    (if (o:hint transformation)
        (p:display-message problem :hint "~a~a" (o:hint transformation) wrong-text)
        (p:display-message problem :hint "~aClick the box~a pointed to by the arrow~p."
                         wrong-text
                         (if (> (length arrows) 1) "es" "")
                         (length arrows)))))

(defmethod p:show-hint-fill-input ((problem base-hints-mixin) tree)
  (multiple-value-bind (arg hint mistake) (guide::arg-fill-in-instructions tree)
    (d:point-to-nodes tree arg)
    (p:display-message problem :hint hint)
    (when mistake
      (p:display-message problem :error mistake))))

(defmethod p:show-hint-already-wrong ((problem base-hints-mixin))
  (p:display-message problem :hint "You've already made a mistake! Click First Mistake to return to the last correct diagram."))

(defmethod p:show-hint-choose-operation ((problem base-hints-mixin) op)
  (if (o:hint op)
      (p:display-message problem :hint "~a" (o:hint op))
      (p:display-message problem :hint "Click the ~a button." (substitute #\Space #\- (string-capitalize (o:name op))))))

(defmethod p:show-hint-finished ((problem base-hints-mixin))
  (p:display-message problem :hint "You're finished! Click Next Problem."))
